<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script src="../js/vue.js" type="text/javascript" charset="utf-8"></script>
	</head>
	<body>
		<div id="root">
			<h2>今天{{time}}邹宜臻吃的是{{food1}}</h2>
			<button @click="change">切换食物</button>
		</div>
		<script type="text/javascript">
			let lunch = '',
				dinner = ''
			const vm = new Vue({
				el: '#root',
				data: {
					isLunch: true,
					food: true
				},
				methods: {
					change() {
						this.isLunch = !this.isLunch
						this.food = !this.food
					}
				},
				computed: {
					time() {
						return this.isLunch ? '中午' : '晚上'
					},
					food1() {
						return this.food ? '臭豆腐' : '腐乳'
					}
				},
				// watch: {
				// 	time: {
				// 		handler(newValue, oldValue) {
				// 			dinner = newValue
				// 			lunch = oldValue
				// 			// console.log(`当前的天气是${newValue},之前的天气是${oldValue}`);
				// 		}
				// 	},
				// 	food1: {
				// 		handler(newValue, oldValue) {
				// 			console.log(
				// 				`当前的时间是${dinner},${dinner}邹宜臻吃的是${newValue};之前的时间是${lunch},${lunch}邹宜臻吃的是${oldValue}`
				// 			);
				// 		}
				// 	}
				// }
			})
			vm.$watch('time', {
				handler(newValue, oldValue) {
					dinner = newValue
					lunch = oldValue
					// console.log(`当前的天气是${newValue},之前的天气是${oldValue}`)
				}
			})
			vm.$watch('food1', {
				handler(newValue, oldValue) {
					console.log(`当前的时间是${dinner},${dinner}邹宜臻吃的是${newValue};之前的时间是${lunch},${lunch}邹宜臻吃的是${oldValue}`);
				}
			})
		</script>
	</body>
</html>
